#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:1_class_dog.py
# author:张世航
# datetime:2024/11/10 17:16
# software: PyCharm
"""
this is function  description 
"""
# import module your need

# 一、定义一个狗类,里面有一个 列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
#        实现狗的买卖交易方法;  打印输出经过2-3次买卖方法后,剩下的各类狗的数量;

class Dog:
    def __init__(self):
        self.dogs = [
            {"color": "black", "quantity": 5, "price": 500},
            {"color": "white", "quantity": 3, "price": 600},
            {"color": "brown", "quantity": 2, "price": 700}
        ]

    def buy(self, color, quantity):
        for dog in self.dogs:
            if dog["color"] == color:
                dog["quantity"] += quantity
                print(f"Bought {quantity} {color} dog(s).")
                return
        print(f"No {color} dogs available.")

    def sell(self, color, quantity):
        for dog in self.dogs:
            if dog["color"] == color:
                if dog["quantity"] >= quantity:
                    dog["quantity"] -= quantity
                    print(f"Sold {quantity} {color} dog(s).")
                    return
                else:
                    print(f"Not enough {color} dogs to sell.")
                    return
        print(f"No {color} dogs available to sell.")

    def print_remaining(self):
        for dog in self.dogs:
            print(f"{dog['color']} dogs: {dog['quantity']} remaining")

# 测试
dog = Dog()
dog.buy("black", 2)
dog.sell("white", 1)
dog.print_remaining()